import Mock from 'mockjs'

// 查询sku列表
export const getSkuPage = async (params: Sku): Promise<ListSkuRes> => {
  const res = await Mock.mock({
    'list|10': [
      {
        'id|+1': 1,
        spuId: 1,
        skuName: '@cword(3, 5)',
        bindService: [
          {
            'id|+1': 1,
            serviceName: '@cword(3, 5)'
          },
          {
            'id|+1': 2,
            serviceName: '@cword(3, 5)'
          },
          {
            'id|+1': 3,
            serviceName: '@cword(3, 5)'
          },
          {
            'id|+1': 4,
            serviceName: '@cword(3, 5)'
          },
          {
            'id|+1': 5,
            serviceName: '@cword(3, 5)'
          }
        ],
        spuName: '@cword(3, 5)',
        originalPrice: '@integer(1, 1000)',
        picUrl: '@image(200x200, @color, @color, @word)',
        stock: '@integer(1, 1000)',
        warnStockLimit: '@integer(1, 1000)',
        price: '@integer(1, 1000)',
        'status|1': [1, 2],
        createTime: 1691727146870
      }
    ],
    total: 100,
    page,
    pageSize: 10
  })
  return res
}

// 查询sku详情
export const getSku = async (id: number) => {
  const res = await Mock.mock({
    'id|+1': 1,
    spuId: 1,
    skuName: '@cword(3, 5)',
    bindService: [
      {
        'id|+1': 1,
        serviceName: '@cword(3, 5)'
      },
      {
        'id|+1': 2,
        serviceName: '@cword(3, 5)'
      },
      {
        'id|+1': 3,
        serviceName: '@cword(3, 5)'
      },
      {
        'id|+1': 4,
        serviceName: '@cword(3, 5)'
      },
      {
        'id|+1': 5,
        serviceName: '@cword(3, 5)'
      }
    ],
    spuName: '@cword(3, 5)',
    originalPrice: '@integer(1, 1000)',
    picUrl: '@image(200x200, @color, @color, @word)',
    stock: '@integer(1, 1000)',
    warnStockLimit: '@integer(1, 1000)',
    price: '@integer(1, 1000)',
    'status|1': [1, 2],
    createTime: 1691727146870
  })
  return res
}

// 新增sku
export const createSku = async (data: Sku) => {
  const res = await Mock.mock({
    isSuccess: true
  })
  return res
}

// 修改sku
export const updateSku = async (data: Sku): Promise<ResStatus> => {
  const res = await Mock.mock({
    isSuccess: true
  })
  return res
}

// 删除商品spu
export const deleteSku = async (id: number): Promise<ResStatus> => {
  const res = await Mock.mock({
    isSuccess: true
  })
  return res
}

/**
 * 文件上传
 * FormData 存有多个文件
 */
export const uploadFile = async (params: FormData): Promise<{ url: string }> => {
  const res = await Mock.mock(['@image(200x200, @color, @word)'])
  return res
}

/**
 * 删除上传文件
 */
export const deleteUploadFile = async (url: stirng[]): Promise<ResStatus> => {
  const res = await Mock.mock({
    isSuccess: true
  })
  return res
}
